#include "bedroom1.h"
#include <QPainter>
#include <QTimer>
#include <QFont>

bedroom1::bedroom1(QWidget *parent)
    : QWidget(parent),
      temperatureValue(0),
      humidityValue(0),
      lightValue(0)
{
    setMinimumSize(800, 600);
    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, &bedroom1::updateData);
    timer->start(1000);
}

void bedroom1::updateData()
{
    temperatureValue = (temperatureValue + 1) % 101;
    humidityValue = (humidityValue + 1) % 101;
    lightValue = (lightValue + 1) % 101;
    update();
}

void bedroom1::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);

    // 绘制背景图片
    QPixmap background(":/images/img/bedroom3_background.png"); // 使用相对路径或资源路径
    painter.drawPixmap(this->rect(), background);

    painter.setRenderHint(QPainter::Antialiasing);

    int diameter = 200;
    int offsetX = 100;
    int offsetY = 100;

    // 绘制温度圆环
    painter.setBrush(Qt::NoBrush);
    painter.setPen(QPen(QColor(70, 70, 200), 15)); // 深蓝色
    painter.drawArc(offsetX, offsetY, diameter, diameter, 90 * 16, -temperatureValue * 3.6 * 16);
    painter.drawText(offsetX + diameter / 2 - 30, offsetY + diameter / 2 + 10, QString("温度: %1°C").arg(temperatureValue));

    // 绘制湿度圆环
    offsetX += 250;
    painter.setPen(QPen(QColor(70, 200, 70), 15)); // 深绿色
    painter.drawArc(offsetX, offsetY, diameter, diameter, 90 * 16, -humidityValue * 3.6 * 16);
    painter.drawText(offsetX + diameter / 2 - 30, offsetY + diameter / 2 + 10, QString("湿度: %1%").arg(humidityValue));

    // 绘制光照圆环
    offsetX += 250;
    painter.setPen(QPen(QColor(200, 200, 70), 15)); // 深黄色
    painter.drawArc(offsetX, offsetY, diameter, diameter, 90 * 16, -lightValue * 3.6 * 16);
    painter.drawText(offsetX + diameter / 2 - 30, offsetY + diameter / 2 + 10, QString("光照: %1%").arg(lightValue));
}
